<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="ja" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<meta http-equiv="Content-Style-Type" content="text/css">
<!-- meta -->
<!-- /meta -->
<title>TM検索</title>
<link rel="stylesheet" type="text/css" href="<%= request.getContextPath() %>/common/css/base.css">
<link rel="stylesheet" type="text/css"
	href="<%= request.getContextPath() %>/common/css/headerfooter.css">
<link rel="stylesheet" type="text/css" href="<%= request.getContextPath() %>/common/css/ulol.css">
<link rel="stylesheet" type="text/css" href="<%= request.getContextPath() %>/common/css/arrow.css">
<link rel="stylesheet" type="text/css"
	href="<%= request.getContextPath() %>/common/css/elements.css">
<!-- admin -->
<link rel="stylesheet" type="text/css"
	href="<%= request.getContextPath() %>/common/css/base_admin.css">
<link rel="stylesheet" type="text/css"
	href="<%= request.getContextPath() %>/common/css/elements_admin.css">
<!-- /admin -->
<script type="text/javascript" src="<%= request.getContextPath() %>/common/js/library.js"></script>
<script type='text/javascript' src='<%= request.getContextPath() %>/dwr/interface/dchDWR.js'></script>
<script type='text/javascript' src='<%= request.getContextPath() %>/dwr/engine.js'></script>
<script type='text/javascript' src='<%= request.getContextPath() %>/dwr/util.js'></script>

<link rel="stylesheet" type="text/css" href="<%= request.getContextPath() %>/common/css/for_winie3.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js" type="text/javascript"></script>
<SCRIPT type="text/javascript"><!--
	/**
	* 検索結果の件数取得処理を呼び出す
	*
	*/
	/*再表示ボタン処理*/
	function pageShow(page){
	    document.getElementById('currentPage').value = page;
		document.frm1.action = "<%= request.getContextPath() %>/outputdata/psi-searchstate";
	   	document.frm1.submit();

	}

	/*
	 * 指定した検索キーワードで検索件数を取得
	 */
	function search(){

		var name_jp =DWRUtil.getValue("name_jp");
		var name_kana = DWRUtil.getValue("name_kana");
		var name_eng = DWRUtil.getValue("name_eng");
		var alias_jp = DWRUtil.getValue("alias_jp");
		var alias_kana = DWRUtil.getValue("alias_kana");
		var alias_eng = DWRUtil.getValue("alias_eng");
		var latitude = DWRUtil.getValue("latitude");
		var longitude = DWRUtil.getValue("longitude");
		var birth_from = DWRUtil.getValue("birth_from");
		var birth_to = DWRUtil.getValue("birth_to");
		var death_from = DWRUtil.getValue("death_from");
		var death_to = DWRUtil.getValue("death_to");
		var person_url = DWRUtil.getValue("person_url");
		var relatede_url = DWRUtil.getValue("relatede_url");
		var psi =DWRUtil.getValue("psi");
		var desc = DWRUtil.getValue("desc");
		var param ={
				name_jp:name_jp,
				name_kana:name_kana,
				name_eng:name_eng,
				alias_jp:alias_jp,
				alias_kana:alias_kana,
				alias_eng:alias_eng,
				latitude:latitude,
				longitude:longitude,
				birth_from:birth_from,
				birth_to:birth_to,
				death_from:death_from,
				death_to:death_to,
				person_url:person_url,
				relatede_url:relatede_url,
				psi:psi,
				desc:desc
		};
		dchDWR.getSearchPsiDataResultCnt(param,searchResultHandler);
	}

	/**
	* 検索結果の件数メッセージを表示する
	* 確認画面からYesを選択した場合、検索結果を取得処理を呼び出す
	*/
	function searchResultHandler(data){
		var dataCnt = eval(data);
		if(dataCnt == 0){
			alert("データが存在しません。");
			return -1;
		}else if(dataCnt == -1){
			alert("検索条件に正しいフォーマットを入力してください。");
			return -1;
		}else if(dataCnt > 0){
			if(confirm(dataCnt+"件あります。表示しますか？")){
				searchAction();
			}
		}
	}

	/**
	* 検索結果取得処理を行う
	*
	*/
	function searchAction(){
		document.frm1.submit();
	}



	//選択ボタン押下でチェックされたデータを親画面に設定
	function selectTm(fieldKey, index, kbn){
		//alert(tmpTblRow);
		if(!window.opener){
			window.close();
		}else{
			//alert(fieldKey);
			//alert($(window.opener.document.getElementById(fieldKey)).tagname);

			$(window.opener.document.getElementById(fieldKey)).empty();
			//window.opener.$("#" + fieldKey).empty();
			$("input:checkbox").each(
					function(i, elem) {

						if ($(elem).attr('checked') == true) {

							var resultVar = resultValSet(i, index, kbn, $(elem).val());
							var resultName  = resultNameSet(i, index, kbn, $(elem).next().val());

							//alert(resultVar[0].attr('type'));

							$(window.opener.document.getElementById(fieldKey)).append(resultVar);
							$(window.opener.document.getElementById(fieldKey)).append(resultName);

							var createSpan = "<span class='tmData'>";
							createSpan += $(elem).next().val();
							createSpan += "</span>";

							$(window.opener.document.getElementById(fieldKey)).append(createSpan);
							$(window.opener.document.getElementById(fieldKey)).append("<br/>");
						}
					}
			);
			window.close();
		}
	}

	function resultValSet(i, index, kbn, val) {

		var createHidden = "<input ";

		if (kbn == "0") {

			createHidden += "type = 'hidden' ";
			createHidden += "name = 'dataDetailList[" + index + "].data' ";
			createHidden += "value = '" + val + "'";
		} else {

			createHidden += "type = 'hidden' ";
			createHidden += "name = 'customDataDetailList[" + index + "].data' ";
			createHidden += "value = '" + val + "'";

		}

		createHidden += " class = 'tmData' />";
		return createHidden;

	}

	function resultNameSet(i, index, kbn, val) {

		var createHiddenName = "<input ";

		if (kbn == "0") {

			createHiddenName += "type = 'hidden' ";
			createHiddenName += "name = 'dataDetailList[" + index + "].dataName' ";
			createHiddenName += "value = '" + val + "'";


		} else {

			createHiddenName += "type = 'hidden' ";
			createHiddenName += "name = 'customDataDetailList[" + index + "].dataName' ";
			createHiddenName += "value = '" + val + "'";

		}

		createHiddenName += " class = 'tmData' />";
		//alert(createHiddenName);
		return createHiddenName;

	}


    var checkedTmSiList = new Array();
    var checkedTmNameList = new Array();
   	/**
	* 結果一覧の行をクリックした場合、選択状態を更新
	*
	*/
	function rowClick(tblRow){
		if(tblRow != undefined ){
		//	tblRow.style.backgroundColor='#e4e4e4';
			var rowIdx=tblRow.rowIndex-1;
			var tmSi = tblRow.cells[2].innerHTML;
			var tmName = tblRow.cells[3].innerHTML;
			if(!document.frm1.elements['tm'+rowIdx].checked){
			  document.frm1.elements['tm'+rowIdx].checked = true;
			  checkedTmSiList[rowIdx]=tmSi;
			  checkedTmNameList[rowIdx]=tmName;
			}else{
			  document.frm1.elements['tm'+rowIdx].checked = false;
			  delete checkedTmSiList[rowIdx];
			  delete checkedTmNameList[rowIdx];
			}
		//	alert(tmpTblRow);
		}
	}

	//TM変更
	function editTm(identifier){
		var popWin2 = window.open('popupTmAdd?action=edit&identifier='+identifier,'child2', 'width=620, height=600, menubar=no, toolbar=no, scrollbars=yes');
	}

	//TM削除
	function delTm(identifier){
		var popWin2 = window.open('popupTmDel?action=del&identifier='+identifier,'child2', 'width=620, height=600, menubar=no, toolbar=no, scrollbars=yes');
	}

--></SCRIPT>

</head>
<body id="dch" onload="window.resizeTo(1000,800);">

<!-- === headerArea === -->
<div id="headerArea"><a name="pageTop" id="pageTop"></a></div>
<!-- === /headerArea === --> <!-- === mainArea === -->

<div id="mainArea">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
	<tr valign="top">
		<td width="20"><img src="<%= request.getContextPath() %>/common/images/spacer.gif"
			width="20" height="4" border="0" alt=""></td>

		<td id="contentsArea">
			<form action="<%= request.getContextPath() %>/outputdata/psi-search" name="frm1" method="get">
			<s:hidden name = "fieldKey"/>
			<s:hidden name = "index"/>
			<s:hidden name = "kbn"/>
			<s:hidden id = "currentPage" name="search.currentPage"/>
			<s:hidden name="popupSign"/>
			<!-- === headerArea === -->
			<div id="headerArea"><a name="pageTop" id="pageTop"></a></div>
			<!-- === /headerArea === --> <!-- === mainArea === -->

			<div id="mainArea">
			<table border="0" cellspacing="0" cellpadding="0" width="100%">
				<tr valign="top">
					<td width="20"><img src="<%= request.getContextPath() %>/common/images/spacer.gif"
						width="20" height="4" border="0" alt=""></td>
					<td id="contentsArea"><!-- === contentsArea === --> <!-- headingLv01Block -->
					<div class="headingLv01Block">
								<h1>PSI検索</h1>
					</div>
					<div class="headingLv02">
						<table border="0" cellspacing="0" cellpadding="5" width="700">
							<tr>
								<td><p><em>検索条件</em></p></td>
							</tr>
						</table>
					</div>
						<div class="tableA01">
							<table border="1" cellspacing="0" cellpadding="5" width="700">
								<tr>
									<!-- ラベル -->
									<th class="lv01B" width="100"><label for="subjectName">日本語名</label></th>
									<!-- 内容 -->
									<td><s:textfield id = "name_jp" name="search.name_jp" size="35" maxlength=""/></td>
									<!-- ラベル -->
									<th class="lv01B" width="100"><label for="subjectReading">日本語カナ</label></th>
									<!-- 内容 -->
									<td><s:textfield id = "name_kana" name="search.name_kana" size="35" maxlength=""/></td>
								</tr>
								<tr>
									<!-- ラベル -->
									<th class="lv01B" width="100"><label for="description">英語名</label></th>
									<!-- 内容 -->
									<td><s:textfield id = "name_eng" name="search.name_eng" size="35" maxlength=""/></td>
									<!-- ラベル -->
									<th class="lv01B" width="100"><label for="description">日本語別名</label></th>
									<!-- 内容 -->
									<td><s:textfield id = "alias_jp" name="search.alias_jp" size="35" maxlength=""/></td>
								</tr>
								<tr>
									<!-- ラベル -->
									<th class="lv01B" width="100"><label for="description">日本語別名カナ</label></th>
									<!-- 内容 -->
									<td><s:textfield id = "alias_kana" name="search.alias_kana" size="35" maxlength=""/></td>
									<!-- ラベル -->
									<th class="lv01B" width="100"><label for="description">英語別名</label></th>
									<!-- 内容 -->
									<td><s:textfield id = "alias_eng" name="search.alias_eng" size="35" maxlength=""/></td>
								</tr>
								<tr>
									<!-- ラベル -->
									<th class="lv01B" width="100"><label for="description">軽度</label></th>
									<!-- 内容 -->
									<td><s:textfield id = "latitude" name="search.latitude" size="35" maxlength=""/></td>
									<!-- ラベル -->
									<th class="lv01B" width="100"><label for="description">緯度</label></th>
									<!-- 内容 -->
									<td><s:textfield id = "longitude" name="search.longitude" size="35" maxlength=""/></td>
								</tr>
								<tr>

									<!-- ラベル -->
									<th class="lv01B" width="100"><label for="description">生年月日</label></th>
									<!-- 内容 -->
									<td><s:textfield id = "birth_from" name="search.birth_from" size="8" maxlength="8"/>&nbsp;～&nbsp;<s:textfield id = "birth_to" name="search.birth_to" size="8" maxlength="8"/>
										<br/>YYYYMMDDで入力してください。</td>
									<!-- ラベル -->
									<th class="lv01B" width="100"><label for="description">没年月日</label></th>
									<!-- 内容 -->
									<td><s:textfield id = "death_from" name="search.death_from" size="8" maxlength="8"/>&nbsp;～&nbsp<s:textfield id = "death_to" name="search.death_to" size="8" maxlength="8"/>
									<br/>YYYYMMDDで入力してください。</td>
								</tr>
								<tr>
									<!-- ラベル -->
									<th class="lv01B" width="100"><label for="description">人物URL</label></th>
									<!-- 内容 -->
									<td><s:textfield id = "person_url" name="search.person_url" size="35" maxlength=""/></td>
									<!-- ラベル -->
									<th class="lv01B" width="100"><label for="description">関連URL</label></th>
									<!-- 内容 -->
									<td><s:textfield id = "relatede_url" name="search.relatede_url" size="35" maxlength=""/></td>

								</tr>
								<tr>
									<th class="lv01B" width="100"><label for="description">PSI</label></th>
									<!-- 内容 -->
									<td><s:textfield id = "psi" name="search.psi" size="35" maxlength=""/></td>
									<!-- ラベル -->
									<th class="lv01B" width="100"><label for="description">説明</label></th>
									<!-- 内容 -->
									<td><s:textfield id = "desc" name="search.desc" size="35" maxlength=""/></td>
								</tr>
							</table>
						</div>

						<!-- pageNaviC01 --> <!-- pageNaviC01 -->
						<div class="pageNaviC01">
							<table border="0" cellspacing="0" cellpadding="5" width="700">
									<tr>
									<td width="298" class="left">
									<p></p>
									</td>
									<td width="130" class="left">&nbsp;</td>
									<td width="130" class="right">
									<p><input type="button" value="検索する" style="width: 130px" onclick="search()">
									</p>
									</td>
								</tr>
							</table>
						</div>



					<div class="headingLv01">
			<table border="0" cellspacing="0" cellpadding="5" width="700">
				<tr>
					<td align="right"><p><em>表示件数：<s:select list="#{'10':'10','20':'20','30':'30','50':'50','100':'100'}" name="search.viewPageCnt"/></em></p></td>
				</tr>
			</table>
			</div>


			<!-- pageNaviB01 -->
			<s:if test='page.totalCnt > 0'>
			<div class="pageNaviB01">
			<table border="0" cellspacing="0" cellpadding="0"  width="800">
				<tr valign="top">
					<td align="left" width="100"><p>結果：${page.totalCnt}件</p></td>
					<td width="50">&nbsp;</td>
					<td align="center">
						<table border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td><p>
								    <s:if test='page.currentPage > 1'><a href="javascript:pageShow(1)">＜最初のページ</a>&nbsp;</s:if>
									<s:if test='(page.currentPage > page.startPage) || (page.previousPage > 0)'><a href="javascript:pageShow(${page.currentPage-1})">&lt;&lt;前を見る</a>…</s:if>&nbsp;&nbsp;
									<s:iterator begin="page.startPage" end="page.endPage" status="num" >
										<s:if test='(#num.index+page.startPage)==(page.currentPage)'>${num.index+page.startPage}</s:if>
										<s:else>
											<a href="javascript:pageShow(${num.index+page.startPage})">${num.index+page.startPage}</a>
										</s:else>
										<s:if test='!(#num.last)'>|</s:if>
									</s:iterator>
									<s:if test='page.endPage < page.totalPage'>&nbsp;…&nbsp;&nbsp;<a href="javascript:pageShow(${page.currentPage+1})">次のページ&gt;&gt;</a></s:if>
									<s:if test='page.currentPage != page.totalPage'>&nbsp;&nbsp;<a href="javascript:pageShow(${page.totalPage})">最後のページ></a></s:if></p>
								</td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
			</div>
			<!-- /pageNaviC01 --> <!-- 検索一覧テーブル -->
			<div class="headingLv02">
			<table border="0" cellspacing="0" cellpadding="5" width="900">
				<tr>
					<td>
					<p><em>データ一覧<br>
					</em></p>
					</td>
				</tr>
			</table>
			</div>
			<!-- pageNaviB01 -->

			<!-- /pageNaviB01 -->
			<!-- tableBlock -->
			<div class="tableBlock">
				<!-- tableA01 -->
				<div class="tableA01">
				<table border="1" cellspacing="0" cellpadding="5" width="100%" style="table-layout: fixed;">
					<tr >
						<th class="lv01B" width="100">選択</th>
						<th class="lv01B" width="100">PSI</th>
						<th class="lv01B" width="100">日本語名</th>
						<th class="lv01B" width="100">日本語カナ</th>
						<th class="lv01B" width="100">英語名</th>
						<th class="lv01B" width="100">日本語別名</th>
						<th class="lv01B" width="100">日本語別名カナ</th>
						<th class="lv01B" width="200">説明</th>
						<th class="lv01B" width="100">英語別名</th>
					</tr>
					<s:iterator value="page.dataList" status="rowId">
						<tr>
							<td>
								<input type="checkbox" value="<s:property value="psi"/>"/>&nbsp;
								<input type="hidden" id = "<s:property value="psi"/>"  value="<s:property value="name_jp"/>"/>
							</td>
							<td style="white-space:normal;"><s:property value="psi"/></td>
							<td><s:property value="name_jp"/></td>
							<td><s:property value="name_kana"/></td>
							<td><s:property value="name_eng"/></td>
							<td><s:property value="alias_jp"/></td>
							<td><s:property value="alias_kana"/></td>
							<td style="white-space:normal;"><s:property value="description"/></td>
							<td><s:property value="alias_eng"/></td>
							</tr>
						</s:iterator>
				</table>
				</div>
			<!-- /tableA01 -->
			</div>
			<div class="pageNaviB01">
			<table border="0" cellspacing="0" cellpadding="0" width="800">
				<tr valign="top">
					<td align="left" width="100">&nbsp;</td>
					<td width="50">&nbsp;</td>
					<td align="center">
							<table border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td><p>
								    <s:if test='page.currentPage > 1'><a href="javascript:pageShow(1)">＜最初のページ</a>&nbsp;</s:if>
									<s:if test='(page.currentPage > page.startPage) || (page.previousPage > 0)'><a href="javascript:pageShow(${page.currentPage-1})">&lt;&lt;前を見る</a>…</s:if>&nbsp;&nbsp;
									<s:iterator begin="page.startPage" end="page.endPage" status="num" >
										<s:if test='(#num.index+page.startPage)==(page.currentPage)'>${num.index+page.startPage}</s:if>
										<s:else>
											<a href="javascript:pageShow(${num.index+page.startPage})">${num.index+page.startPage}</a>
										</s:else>
										<s:if test='!(#num.last)'>|</s:if>
									</s:iterator>
									<s:if test='page.endPage < page.totalPage'>&nbsp;…&nbsp;&nbsp;<a href="javascript:pageShow(${page.currentPage+1})">次のページ&gt;&gt;</a></s:if>
									<s:if test='page.currentPage != page.totalPage'>&nbsp;&nbsp;<a href="javascript:pageShow(${page.totalPage})">最後のページ></a></s:if></p>
								</td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
			</div>
			<div class="pageNaviC01">
			<table border="0" cellspacing="0" cellpadding="10" width="900">
				<tr>
					<td width="298" class="left">
					<p><input type="button" value="キャンセル" style="width: 100px"	onclick="window.close();"></p>
					</td>
					<td width="130" class="left">&nbsp;</td>
					<td width="130" class="right">
					<p><input type="button" value="選択" style="width: 130px" onclick="selectTm('<s:property value="fieldKey"/>','<s:property value="index"/>','<s:property value="kbn"/>')"></p>
					</td>
				</tr>
			</table>
		</div>
			</s:if>
			<!-- === /mainArea === -->
			<!-- === /contentsArea === --></td>
			</table>
			</div>
		</form>

		</td>
<!-- === /mainArea === -->
		<td width="16"><img src="<%= request.getContextPath() %>/common/images/spacer.gif"	width="16" height="4" border="0" alt=""></td>


	</tr>
</table>
</div>

<!-- === footerArea === -->
<div id="footerArea"><!--#include virtual="<%= request.getContextPath() %>/common/include/footer.html" -->
</div>
<!-- === /footerArea === -->
</form>
</body>
</html>
<!-- System Architect is COOBA Corp
	Copyright 2010 COOBA Corp All rights reserved -->